# _*_ coding: utf-8 _*_
from odoo import models, api, fields, _
from odoo.exceptions import ValidationError


class OLProductTemplateExtend(models.Model):
    _inherit = "product.template"

    tmpl_purchase_limit_control = fields.Boolean(string="Template Purchase Limit Control")
    tmpl_purchase_limit = fields.Float(string="Template Purchase Limit")

    _sql_constraints = [
        ('tmpl_purchase_limit_must_greater_then_0',
         'check((not tmpl_purchase_limit_control) or (tmpl_purchase_limit_control and tmpl_purchase_limit>0))',
         'Purchase limit must greater then 0 !')
    ]
    #
    # @api.constrains("tmpl_purchase_limit")
    # def _constraint_tmpl_purchase_limit(self):
    #     for template in self:
    #         if template.tmpl_purchase_limit_control and template.tmpl_purchase_limit < 0:
    #             raise ValidationError(_("Purchase limit must greater then 0 !"))
